package com.example.lastwork.controller;


import com.example.lastwork.common.controller.LogicController;
import com.example.lastwork.dao.UserDao;
import com.example.lastwork.dto.RestDTO;
import com.example.lastwork.entity.User;
import com.example.lastwork.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "用户服务接口")
@RestController
@RequestMapping("/UserController")
public class UserController extends LogicController<UserService, UserDao, User, Long> {
    public UserController(@Autowired UserService service){
        super(service);
    }

    @ApiOperation("用户登录")
    @RequestMapping(value = "/getUserByIdByPassword",method = RequestMethod.POST)
    public RestDTO<Object> getUserByIdByPassword(@ApiParam("用户编号") Long userId, @ApiParam("用户密码") String password){
        User user = getService().getUserByIdByPassword(userId, password);
        if (user==null){
            return RestDTO.failure(401,"登陆失败");
        }else {
            return RestDTO.success(user);
        }
    }
}
